<?php
/**
 * User: Administrator
 * Note: 后台首页
 */
namespace Admin\Controller;

use Think\Controller;

class IndexController extends BaseController
{
    public function index()
    {
        // 获取系统信息
        $info = array(
            'info_00' => $_SERVER['SERVER_NAME'],//域名
            'info_01' => PHP_OS,//服务器操作系统
            'info_02' => $_SERVER['SERVER_ADDR'],//服务器IP地址
            'info_03' => $_SERVER['SERVER_SOFTWARE'],//服务器软件配置
            'info_04' => php_sapi_name(),//PHP运行方式
            'info_05' => $_SERVER['DOCUMENT_ROOT'],//项目路径
        );
        $this->assign('info', $info);
        // 获取平台公告
        $notice = M('notice')->where(array('status'=>'1'))->order('id desc')->limit(5)->select();
        if ($notice) {
            foreach ($notice as &$item) {
                $item['title'] = mb_substr($item['title'], 0, 15, 'utf-8');
            }
        }
        $this->assign('notice', json_encode($notice));

        // // 本月，k线图
        $start_time = strtotime(date('Y-m-d')) + 86400;
        $end_time   = $start_time + 86400;
        $kline      = array('day'=>array(),'data'=>array());
        // 30天
        for ($i = 0;$i < 30;$i++) {
            $start_time -= 86400;
            $end_time   -= 86400;
            // 横轴日期
            array_unshift($kline['day'], date('Y-m-d', $start_time));
            // 变动
            $k_map['login_time'] = array(array('egt',$start_time),array('lt',$end_time));
            $data2 = M('log_admin')->where($k_map)->count();
            // $earnNum = money_4point($data2['num']);
            $data = $data2 ? $data2 : '0';
            array_unshift($kline['data'], $data);
        }
        $this->assign('kline', json_encode($kline));

        $this->assign('meta_title', '管理后台');
        $this->display();
    }
}
